import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    currentInfo: {},
    searchInfo: [],
    token: localStorage.getItem('token') ? localStorage.getItem('token') : '',
    isLogin:false ,// 判断是否登录
  },
  getters: {
    getStorage(state) {
      if (!state.token) {
        state.token =JSON.parse(localStorage.getItem(key))
      }
      return state.token
    }
  },
  mutations: {
    saveCurrent(state, payload) {
      state.currentInfo = payload
      console.log(state.currentInfo);
    },
    searchInfo(state, payload) {
      state.searchInfo = payload
      console.log(state.searchInfo);
    },
    setToken(state,payload){
      state.token = payload
      localStorage.setItem('token',payload)
      console.log(state.token);
    },
    removeToken(state, value){  // 删除token
      localStorage.removeItem('token');
  },
  },
  actions: {
    // 放异步
    
  },
  modules: {
  }
})
